<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>退货审核</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
      <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
      <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body> 
    	   <div class="easyui-container-fluid">
              <div class="easyui-panel" style="border: none;">
                 <div class="nav" id="nav">
                    
                 </div>
                 <div class="easyui-panel" style="padding-top:20px;">
                 	<form id="ff">
                 	<div style="margin-bottom:20px;">
                 		<label class="item-label">年份：</label>
                 		<select class="easyui-combobox" name="year" id="year" style="width:80px;"></select>
                 		<label class="item-label">月份：</label>
                		<select class="easyui-combobox" name="month" id="month" style="width:80px;">
                		</select>
                		<!-- 
                		<label class="item-label">周  ：</label>
                		<select class="easyui-combobox" name="week" id="week" style="width:80px;"></select>
                		 -->
                       	<label class="item-label">渠道：</label>
                       	<select id="channel" name="channelCode" class="easyui-combobox" style="width: 100px;">
                      	</select>
                 	</div>
                    <div style="margin-bottom:20px;">
                       
                    </div>
                      <div style="margin-bottom:20px;text-align:center;">
                        <a class="easyui-linkbutton c8" style="width:80px;" onclick="searchBy()">查询</a>
                      </div>
                      </form>
                 </div>
                  <div class="table-wrapper" style="float: left;width: 45%;">
                   <table id="datagrid_mall" class="easyui-datagrid" style="width:100%;" data-options="fitColumns:true,scrollbarSize:0,emptyMsg:'请选择周期'">
                     <thead>
                       <tr>
                         <th data-options="field:'id',checkbox:true,align:'center'"></th>
                         <th data-options="field:'mallName',align:'center',formatter:mallFormatter" width="80">商场</th>                 
                         <th data-options="field:'originalCount',align:'center'" width="160">原始销量</th>
                         <th data-options="field:'obliterateCount',align:'center'" width="160">核减后销量</th>
                         <th data-options="field:'total',align:'center',formatter:difFormatter" width="160">差距</th>
                         <th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th> 
                       </tr>
                     </thead>
                     <tbody>
                     </tbody>
                   </table>
                 </div>
                  <div class="table-wrapper" style="float: left;width: 45%;margin-left: 20px;">
                   <table id="datagrid_category" class="easyui-datagrid" style="width:100%;" data-options="fitColumns:true,scrollbarSize:0,emptyMsg:'请选择周期'">
                     <thead>
                       <tr>
                         <th data-options="field:'id',checkbox:true,align:'center'"></th>
                         <th data-options="field:'categoryName',align:'center',formatter:categoryFormatter" width="80">品类</th>                 
                         <th data-options="field:'originalCount',align:'center'" width="160">原始销量</th>
                         <th data-options="field:'obliterateCount',align:'center'" width="160">核减后销量</th>
                         <th data-options="field:'total',align:'center',formatter:difFormatter" width="160">差距</th>
                         <th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th> 
                       </tr>
                     </thead>
                     <tbody>
                     </tbody>
                   </table>
                 </div>
              </div>
         </div>
    </body>
    <script type="text/javascript">
        $(function(){
            setNav();

            aRecords("退货审核","/webapp/pages/channel/salesDetail/returnCheck")
            initChannelSelect("channel");
            // initWeekSelect("week");
            initMonthSelect("month");
            initYearSelect("year");
            $("#datagrid").datagrid({
               // pagination:true,
               rownumbers:true,
               toolbar:[{
                    text:'批号禁用',
                    handler:function(){
                      
                    }
                }]
           });
        });
     function actions(val,row){
         return  "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
      "onclick='disableOne(\""+row.id+"\")'>禁用</a>";
     }
     function edit(id){
       window.location.href = "./add.html?id="+id;
     }
     function disableOne(data){
          $.messager.confirm("提示","您确定禁用该记录吗？",function(flag){
               if(flag){
                  $.ajax({
                      url:config.url+"/channelSalesData/"+data,
                      type:'DELETE',
                      xhrFields:{withCredentials:true},
                      success:function(data){
                          $.messager.alert("提示","操作成功");
                          $.ajax({
                             url:config.url + "/mall",
                             type:"get",
                             data:{size:10},
                             xhrFields:{withCredentials:true},
                             success:function(data){
                                $("#datagrid").datagrid({data:data.content}).datagrid("getPager").pagination({
                                  pageList:[10,15,20,25,30,35,40,50,100],
                                  displayMsg:"共"+data.totalElements+"条记录"
                                });
                             },
                             error:function(data){
                                console.log(data);
                             }
                         });
                      },
                      error(XMLHttpRequest,textStatus,thrown){

                      }
                  });
               }
          });
     }

     function searchBy(){
        var data = getFormData(document.getElementById("ff"));
        console.log(data);
        $.ajax({
            url:config.url + "/returnCheck/mall",
            type:"get",
            data:transfer(data),
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
              },
            success:function(data){
               $("#datagrid_mall").datagrid({data:data.content}).datagrid("getPager").pagination({
                 pageList:[10,15,20,25,30,35,40,50,100],
                 displayMsg:"共"+data.totalElements+"条记录"
               });
               $.messager.progress("close");
            },
            error:function(data){
               console.log(data);
               $.messager.progress("close");
            }
        });
        
        
        $.ajax({
             url:config.url + "/returnCheck/category",
             type:"get",
             data:transfer(data),
             xhrFields:{withCredentials:true},
             beforeSend:function () {
                 $.messager.progress({
                     title:"请稍等",
                     interval:50,
                     text:"数据加载中..."
                 });
               },
             success:function(data){
                $("#datagrid_category").datagrid({data:data.content}).datagrid("getPager").pagination({
                  pageList:[10,15,20,25,30,35,40,50,100],
                  displayMsg:"共"+data.totalElements+"条记录"
                });
                $.messager.progress("close");
             },
             error:function(data){
                console.log(data);
                $.messager.progress("close");
             }
         });
     }
     function mallFormatter(value,row,index){
	     return value+"|("+row.mallCode+")";
     }
     function categoryFormatter(value,row,index){
	     return value+"|("+row.categoryCode+")";
     }
     function difFormatter(value,row,index){
         if(row.originalCount<=0){
        	 return "0.00%";
         }else{
        	 if(row.obliterateCount<=0){
        		 return "100.00%";
        	 }else{
        		 return (row.originalCount-row.obliterateCount)*100/row.originalCount + '%';
        	 }
         }
     }
    </script>
</html>